package com.education.user.service;


import com.education.user.mapper.SysInfoMsgMapper;
import com.education.user.pojo.SysInfoMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class SysInfoMsgService {

    @Autowired
    private SysInfoMsgMapper sysInfoMsgMapper;
    //根据id查询消息详情
    public  SysInfoMsg findById(Integer id){
        return sysInfoMsgMapper.selectByPrimaryKey(id);
    }

    /**
     * 根据用户id查询消息
     */
    public List<SysInfoMsg> findByMsg(SysInfoMsg sysInfoMsg){
        return sysInfoMsgMapper.select(sysInfoMsg);
    }

    //查询全部消息
    public List<SysInfoMsg> select(Integer userId) {
        SysInfoMsg sysInfoMsg = new SysInfoMsg();
        sysInfoMsg.setUserId(userId);
        return sysInfoMsgMapper.select(sysInfoMsg);
    }

    //查询全部消息
    public List<SysInfoMsg> selectAll(Integer userId) {
        Example example = new Example(SysInfoMsg.class);
        //注意：排序使用的是列名
        example.setOrderByClause("create_time DESC");
        //条件查询使用的是属性名
        example.createCriteria().andEqualTo("userId", userId).orIsNull("userId");
        return sysInfoMsgMapper.selectByExample(example);
    }

    //查询全部消息
    public List<SysInfoMsg> select2(Integer userId) {
        SysInfoMsg sysInfoMsg = new SysInfoMsg();
//        sysInfoMsg.setUserId(userId);
        return sysInfoMsgMapper.select(sysInfoMsg);
    }

    //添加消息
    public Integer insert(SysInfoMsg sysInfoMsg) {
        return sysInfoMsgMapper.insert(sysInfoMsg);
    }


    //查询总数
    public Integer findCount(Integer userId) {
        SysInfoMsg sysInfoMsg = new SysInfoMsg();
        sysInfoMsg.setUserId(userId);
        return sysInfoMsgMapper.selectCount(sysInfoMsg);
    }

    //根据idList查询消息
    public List<SysInfoMsg> findByIds(List<Integer> idList,Integer userId,Integer type){
        return sysInfoMsgMapper.findByIds(idList,userId,type);
    }


    //根据idList查询消息
    public List<SysInfoMsg> findNotByIds(List<Integer> idList,Integer userId,Integer type){
        return sysInfoMsgMapper.findNotByIds(idList, userId, type);
    }

}
